<?php

namespace app\admin\model;


use think\Model;


class Setting extends Model
{

    // 表名
    protected $name = 'setting';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    static public function getSettings()
    {
        $allData = self::select(); 
        $data = [];
        foreach ($allData as $d) {
            $data[$d['name']] = $d['value'];
        }

        return $data;
    }

    static public function getSingleSetting($name, $allSettings = [])
    {
        if (empty($allSettings)) {
            $allSettings = self::getSettings();
        }
        if (empty($allSettings)) {
            return '';
        }
        if (!isset($allSettings[$name])) {
            return '';
        }
        return $allSettings[$name];
    }

    static public  function getRentCancel()
    {
        $data = self::where('name', 'rent_cancel')->find();
        return $data->value;
    }

    static public  function getAddCredit()
    {
        $data = self::where('name', 'add_credit')->find();
        return $data->value;
    }

    static public  function getDeclineCredit()
    {
        $data = self::where('name', 'decline_credit')->find();
        return $data->value;
    }

    static public  function getRechargeBonus()
    {
        $data = self::where('name', 'recharge_bonus')->find();
        return $data->value;
    }

    static public  function getRefundMoney()
    {
        $data = self::where('name', 'refund_money')->find();
        return $data->value;
    }

    static public  function getRentRefund()
    {
        $data = self::where('name', 'rent_refund')->find();
        return $data->value;
    }

    static public function getRentAtLeastMin()
    {
        $data = self::where('name', 'rent_at_least_min')->find();
        return $data->value;
    }

    static public function getRentReserveAdvanceDay()
    {
        $data = self::where('name', 'rent_reserve_advance_day')->find();
        return $data->value;
    }

    static public function getUnlockInadvanceMin()
    {
        $data = self::where('name', 'unlock_inadvance_min')->find();
        return $data->value;
    }

}
